home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
003.dms
/
003.adf
/
TEXT
/
chapter7.txt
< prev
next >
Wrap
Text File
|
1992-09-02
|
10KB
|
289 lines
The Absolute Beginners Guide To Amos
-------------------------------------
Chapter Seven
-------------
Before we start here are the answers to the quiz in chapter six.
1. B 2. A
3. C 4. A
5. B 6. A
7. A 8. B
9. A 10. A
If you got less than five correct then please re-read the corresponding
chapters. If you got five to eight correct you are doing great if you got
nine or more congratulations and keep it up.
---------------------------------------------------------------------------
Now I think it`s time to learn some new commands I have picked out some
commands that are fairly straight forward and some others that are a bit more
complex but ones that you are going to need to know about. You shouldn`t
have too much trouble with this lot, keep making those notes and refer to
them as much as needed. I have been using Stos/Amos for quite a few years
now and I still refer to my note book, especially for things like the Amos
file selector syntax, I can never remember how that goes.
Anyway enough yapping let`s learn something new.
BOOM
----
This is fun, BOOM is one of three sound effects already built into Amos
for us. It doesn`t need any variables and is a stand alone command, you just
simply put BOOM anywhere in your program that you want a BOOM sound such as
an explosion for example. Admittedly BOOM doesn`t sound that great but it is
simple and memory efficient.
BELL
----
The same as BOOM except giving a simple single bell sound.
SHOOT
-----
Again the same as above but can be used as a gun firing sound effect.
EXAMPLE7.Amos will give you an idea of how to use these effects.
WAIT N
-------
This command is almost identical to WAIT KEY but more flexible, the N stands
for a number, any number, for example, WAIT 50, would halt the program in
it`s tracks for one second and then continue.
WAIT has nothing to do with key presses or the user so put that out of your
mind now. WAIT just WAITs around for N 50ths of a second, some examples:
WAIT 1 REM Wait for 1/50th of a second
WAIT 25 REM Wait for half a second
WAIT 50 REM wait for one second
WAIT 100 REM Wait for two seconds
WAIT 500 REM Wait for ten seconds.
And so on and so forth.
RND (N)
-------
RND is short for RANDOM this smart little fellow generates RaNDom numbers for
us in any range we want, I will explain by example:
RND (5) REM Will produce a random number from 0 to 4 (but not 5)
RND (5)+1 REM Will give a random number from 1 to 5, it is the same as
above but 1 is added to the result (+1)
RND (100) REM Generates a random number from 0 to 99, if we wanted it to
include 100 in it`s calculations we just add a +1
RND (100)+1 REM Like this.
That`s all very well but to use a RaNDom number we will need to assign it to
a variable so we can manipulate it, well luckily that is quite easy:
A=RND(5) REM A equals a random number 0 to 4
A=RND (5)+1 REM A equals a random number 1 to 5
A=RND (100) REM A equals a random number 0 to 99
A=RND(100)+1 REM A equals a random number 1 to 100
A, of course, can be any variable name you wish like GUESS or RN etc.
So, we have a variable containing a random number, we know the range of the
number but we will have to interrogate the variable to find out the generated
random number cos it won`t tell us unless we ask:
IF A=1 then BOOM REM IF the variable A is equal to one then play the
BOOM sound effect.
Well that is one way of finding out if the random number is equal to one,
but that approach is pretty limited.
Let`s suppose we have a simple guessing game where the computer generates
a RaNDom number from 0 to 99, the user then INPUTS his guess and the
computer responds with a TOO LOW, TOO HIGH or CORRECT message.
How do we get Amos to check for higher, lower and equal to the RaNDom number?
IF GUESS=RN then bell REM GUESS is the users INPUT, RN the computers
RaNDom number, if equal sound the BELL effect.
It`s the equals sign that does it.
How about higher or lower?
IF GUESS>RN THEN BOOM REM If GUESS is more than the RaNDom number
THEN sound the BOOM effect.
IF GUESS <RN THEN SHOOT REM If GUESS is less than RN THEN SHOOT
Notice in the last example how close the line of code is to the actual
English translation.
Here is the listing of the number guessing game which is EXAMPLE7.Amos
REM Number Guess
`
`
PAPER 0: HIDE : CLS 0
SCORE=0
L1:
RN=RND(100)
L2:
CLS 0
LOCATE 0,0: PRINT "SCORE ";score
LOCATE 0,4: LINE INPUT "What is your guess? (0-99) ";guess
IF GUESS=RN THEN LOCATE 0,20:PRINT "CORRECT":BELL:INC SCORE:WAIT 100: GOTO L1
IF GUESS>RN THEN LOCATE 0,20: PRINT "TOO HIGH": SHOOT: WAIT 100: GOTO L2
IF GUESS<RN THEN LOCATE 0,20: PRINT "TOO LOW": BOOM: WAIT 100:GOTO L2
REM Amos will never get to this line! Do you know why?
Don`t panic there are some new commands to cover here that we haven`t looked
at yet, here is the breakdown of every part of EXAMPLE7.Amos,
PAPER 0: HIDE: CLS 0
--------------------
We know all about these.
SCORE=0
-------
Set the variable SCORE to 0. We have covered variables previously.
L1:
---
Right this is the first part of the program we haven`t seen before.
L1 is a Label it`s not a command as such, it is a marker, so that later on we
can tell Amos to GOTO the marker if certain conditions are met.
The use of labels will become a lot clearer in a minute when we take a look
at the infamous GOTO instruction.
A few things to remember about labels is they must end in a colon,
like this, LABEL: and they can contain any string of text or numbers
including the underscore character like this LABEL_1:
RN=RND (100)
-----------
This line is explained earlier in this chapter.
L2:
--
Is the second label, we have to make sure labels are not the same, we can`t
have L1: twice so to keep it simple I`ve use L2:
CLS 0
-----
You know what this does, if not look at EXAMPLE7.Amos
LOCATE 0,0:
----------
Right this is a new command we haven`t yet covered. LOCATE literally LOCATES
the coordinates you give it and sets the text cursor to that position on the
screen and anything PRINTed after the LOCATE instruction will be PRINTed at
the text coordinate supplied. In the above line the coordinates we have
supplied LOCATE with are 0 and 0 this means, starting from the top left edge
of the screen, 0 across and 0 down so in effect we are telling Amos to set
the PRINTing position to the top left edge of the screen.
PRINT "SCORE ";SCORE
--------------------
The next part of the line uncovers two features of Amos we have looked at
separately but not glued together in this form. What is happening here is we
Are telling the PRINT command to PRINT the word SCORE plus a space and then
telling Amos to get ready for a variable with the ; we then supply the
variable which is the SCORE variable we defined to 0 at the start of the
program. Can you work out what the screen would look like if SCORE=7?
It would look like this:
SCORE 7
If you thought it would look like this:
SCORE SCORE 7
Then you must understand that the first word is enclosed in quotes which as
we discussed earlier means that Amos will PRINT exactly what is inside the
quotes the second word SCORE is a variable which in this example equalled
7 so Amos PRINTED the value of SCORE and not the string.
LOCATE 0,4:
----------
The same as above but sets the PRINT position to 0 across 4 down.
LINE INPUT "What is your guess? (0-99) ";guess
----------------------------------------------
We have discussed LINE INPUT quiet thoroughly before, check your notes and
read the REMs in EXAMPLE7.Amos
I shall break the next line up into two.
IF GUESS=RN THEN LOCATE 0,2: PRINT "CORRECT"
--------------------------------------------
IF the variable GUESS (The players number, taken from the LINE INPUT)
is equal to RN (RN is the RaNDom number generated earlier) THEN set the
PRINT position to 0 cells across and 2 cells down the screen, then PRINT
the string of characters in quotes "CORRECT"
BELL: INC SCORE: WAIT 100: GOTO L1
----------------------------------
The second part of the line continues with, make the BELL sound, INCrement
the players SCORE by one, wait 2 seconds then GOTO the label marked L1.
Notice we didn`t have to say GOTO L1: (I.e. we didn`t have to use the colon)
The GOTO command is the only stranger here and must be the most controversial
command in any programming language ever. Some hate to use it some don`t
care, some swear by it. At this stage of your learning I wouldn`t worry
about it at all. As far as I am concerned I will use a GOTO if it is
necessary or if it keeps the program simple. Sometime In the future I guess
you will come to your own decision about using the GOTO command or not.
Personally I can`t see what all the fuss is about. So basically GOTO simply
goes to the label you have told it to and carries on executing the program
from there.
Everything in the next two lines of the program have been explained.
So that wraps up this chapter, I hope you remembered to take notes on this
lot as we have exams coming up for you very soon!
Now is a good time to load up EXAMPLE7.Amos.
End of chapter seven.